<template>
    <div class="company">
        <search-form :searchArray="searchArray" :searchObj="searchObj" @search="getList">
            <el-button class="btn search mL20" @click="addCompany">新增</el-button>
        </search-form>
        <elTable :formData="formData" @getList="getList">
                <el-table-column prop="name" label="公司名称" align="center"></el-table-column>
                <el-table-column prop="createTime" label="企业性质" align="center">
                    <template slot-scope="scope">
                        {{scope.row.companyNature && scope.row.companyNature.name || ''}}
                    </template>
                </el-table-column>
                <el-table-column prop="organizingCode" width="120px" label="组织机构代码" align="center"></el-table-column>
                <el-table-column prop="mobile" label="手机号" align="center"></el-table-column>
                <el-table-column prop="contacts" label="联系人" align="center"></el-table-column>
                <el-table-column prop="statusMessage" label="审核状态" align="center"></el-table-column>
                <el-table-column prop="contacts" label="省市区" align="center">
                    <template slot-scope="scope">
                        {{`${scope.row.province && scope.row.province.name || ''} ${scope.row.city && scope.row.city.spell || ''} ${scope.row.area && scope.row.area.name || ''}`}}
                    </template>
                </el-table-column>
                <el-table-column prop="openAccountStatusMessage" label="平安开户状态" align="center"></el-table-column>
                <el-table-column prop="bindBankStatusMessage" label="银行绑卡状态" align="center"></el-table-column>
                <el-table-column prop="shopTypeMessage" label="店铺类型" align="center"></el-table-column>
                <el-table-column prop="olineStatusMessage" label="卖家开业审核状态" align="center"></el-table-column>
                <el-table-column prop="sourceMessage" label="注册来源" align="center"></el-table-column>
                <el-table-column prop="createTime" label="创建时间" align="center">
                    <template slot-scope="scope">
                        {{$normalTime(scope.row.createTime)}}
                    </template>
                </el-table-column>
                <el-table-column prop="action" label="操作" align="center" width="120px;" fixed="right">
                    <template slot-scope="scope">
                        <el-button type="text"  @click="auditCompany(scope.row)" v-if="scope.row.status == 1">审核</el-button>
                        <el-button type="text"  @click="editer(scope.row)">编辑</el-button>
                        <el-button type="text"  @click="goJylb(scope.row)">经营类别</el-button>
                        <el-button type="text"  @click="goSqzl(scope.row)">申请资料</el-button>

                    </template>
                </el-table-column>
        </elTable>
        <dialogs
        title="审核"
        :visible="showAuditDialog"
        width="500px"
        @confirm="confirmChangeStatus"
        class="sh-dialog"
        >
          <el-form v-model="companyStatusForm" label-width="80px">
              <el-form-item label="状态">
                  <el-select  v-model="companyStatusForm.status" placeholder="请选择状态">
                      <el-option value="-1" label="拒绝" ></el-option>
                      <el-option value="2" label="通过" ></el-option>
                  </el-select>
              </el-form-item>
              <el-form-item label="审核原因">
                  <textarea v-model.trim="companyStatusForm.auditLog.memo" placeholder="请输入审核原因"></textarea>
              </el-form-item>
          </el-form>
        </dialogs>
    </div>
</template>
<script>
import elTable from "@/components/xForm/elTable"
import { mapGetters } from 'vuex'
export default {
    name: 'company',
    components: {
        elTable
    },
    data () {
        return {
            showAuditDialog: {
                show: false
            },
            companyStatusForm: {
                status: '',
                auditLog: {
                    memo: ''
                }
            },
            formData: {
                currentPage: 1,
                pageSize: 10,
                total: 0,
                data: []
            },
            searchObj: {
                name: '',
                type: '',
                organizingCode: '',
                status: '',
                isVip: '',
                openPinganAccountStatus: '',
                bindBankStatus: '',
                shopType: '',
                olineStatus: '',
                source: '',
                provinceId: '',
                cityId: '',
                areId: ''
            },
            searchArray: [
                {
                    type: 'input',
                    value: '',
                    label: '公司名称',
                    placeholder: '请输入公司名称',
                    key: 'name'
                },
                {
                    type: 'select',
                    value: '',
                    label: '企业性质',
                    placeholder: '请选择',
                    key: 'type',
                    list: []
                },
                {
                    type: 'input',
                    value: '',
                    label: '组织机构代码',
                    placeholder: '请输入组织机构代码',
                    key: 'organizingCode'
                },
                {
                    type: 'area',
                    value: {value: []},
                    label: '区域',
                    key1: 'provinceId',
                    key2: 'cityId',
                    key3: 'areId'
                },
                {
                    type: "select",
                    placeholder: "请选择",
                    filterable: false,
                    value: "",
                    width: '',
                    label: '审核状态',
                    key: 'status',
                    list: [
                    ]
                },
                {
                    type: "select",
                    placeholder: "请选择",
                    filterable: false,
                    value: "",
                    width: '',
                    label: 'vip',
                    key: 'isVip',
                    list: [
                        {
                            label: '不是',
                            value: 0
                        },
                        {
                            label: '是vip买家',
                            value: 1
                        }
                    ]
                },
                {
                    type: "select",
                    placeholder: "请选择",
                    filterable: false,
                    value: "",
                    width: '',
                    label: '平安开户状态',
                    key: 'openPinganAccountStatus',
                    list: [
                    ]
                },
                {
                    type: "select",
                    placeholder: "请选择",
                    filterable: false,
                    value: "",
                    width: '',
                    label: '绑卡状态',
                    key: 'bindBankStatus',
                    list: [
                    ]
                },
                {
                    type: "select",
                    placeholder: "请选择",
                    filterable: false,
                    value: "",
                    width: '',
                    label: '店铺类型',
                    key: 'shopType',
                    list: [
                    ]
                },
                {
                    type: "select",
                    placeholder: "请选择",
                    filterable: false,
                    value: "",
                    width: '',
                    key: 'olineStatus',
                    label: '卖家开业审核状态',
                    list: [
                        {
                            label: '待申请',
                            value: 0
                        },
                        {
                            label: '已申请',
                            value: 1
                        },
                        {
                            label: '审核通过',
                            value: 2
                        },
                        {
                            label: '审核未通过',
                            value: 3
                        }
                    ]
                },
                {
                    type: "select",
                    placeholder: "请选择",
                    filterable: false,
                    value: "",
                    width: '',
                    key: 'olineStatus',
                    label: '注册来源',
                    key: 'source',
                    list: [
                    ]
                },
            ],
            currentItem: {},
        }
    },
    computed: {
        ...mapGetters({
            enumAll: 'common/getEnumAll'
        }),
    },
    created () {
        this.init()
    },
    methods: {
        init () {
            this.$set(this.searchArray[4], 'list', this.enumAll['EnumCompanyStatus'] )
            this.$set(this.searchArray[6], 'list', this.enumAll['EnumCompanyOpenAccountStatus'] )
            this.$set(this.searchArray[7], 'list', this.enumAll['EnumBindBackStatus'] )
            this.$set(this.searchArray[8], 'list', this.enumAll['EnumShopType'] )
            this.$set(this.searchArray[10], 'list', this.enumAll['EuumSouce'] )
            this.getList()
        },
        // 审核
        auditCompany (item) {
            this.currentItem = item
            this.showAuditDialog.show = true
        },
        // 确定审核
        confirmChangeStatus () {
            const {companyStatusForm: {status, auditLog: {memo}}, currentItem: {id}} = this
            if (!status) {
                this.$message.error('请选择审核状态')
                return
            }
            if (!memo) {
                this.$message.error('请输入审核原因')
                return
            }
            let param = {
                status,
                auditLog: {
                    memo
                },
                id
            }
            this.$loading(true)
            this.$api.userManage.putChangeCompanyStatus(param).then(r => {
                this.$message.success(r.message)
                this.showAuditDialog.show = false
                setTimeout(() => {
                    this.getList()
                }, 1000)
            }).finally(() => {
                this.$loading(false)
            })
        },
        getList(status = true) {
            if (!status) this.formData.currentPage = 1
            const {searchObj, formData: {currentPage, pageSize}} = this
            this.$loading(true)
            let param = {}
            param = {
                currentPage,
                pageSize
            }
            for (let k in searchObj) {
                if (searchObj[k] !== '') {
                    param[k] = searchObj[k]
                }
            }
            this.$loading(true)
            this.$api.userManage.getCompanyList(param).then(r => {
                this.formData.data = r.data && r.data.list || []
                this.formData.total = r.data && r.data.total || 0
            }).finally(() => {
                this.$loading(false)
            })
        },
        editer (item) {
            this.$router.push({
                path: `/userManage/company/add/1/${item.id}`,
                query: {

                }
            })
        },
        addCompany () {
            this.$router.push({
                path: '/userManage/company/add/0/0'
            })
        },
        goJylb (item) {
            this.$router.push({
                path: `/userManage/company/businessCategory/${item.id}`
            })
        },
        goSqzl (item) {
            this.$router.push({
                path: `/userManage/company/applyData/${item.id}`
            })
        }
    }
}
</script>
<style lang="scss" scoped>
.company {
    .search-form {
        margin-bottom: 16px;
    }
    ::v-deep.sh-dialog {
        .el-form {
            .el-select {
                width: 100%;
            }
            textarea {
                width: 100%;
                height: 100px;
                border: 1px solid #ddd;
                box-sizing: border-box;
                padding: 10px;
                &:focus {
                    outline: none;
                }
            }
        }
    }
}
</style>